///////////////////////////////////////////////////////////////
// File: "CCreditsState.cpp"
// Author: James Gonzalez(JG)
// Purpose: The Credits for the game
///////////////////////////////////////////////////////////////

#include "CCreditsState.h"
#include "CWiimote.h"
#include "../Wrappers/CSGD_DirectInput.h"
#include "CBitmapFontEngine.h"
#include "CMusicManager.h"
#include "CSoundManager.h"
#include "CTransitionScreen.h"
#include "CMainMenuState.h"
#include "..//Wrappers/CSGD_TextureManager.h"
#include "CGame.h"
#include "CLevelSelectState.h"
#include "CGamePlayState.h"
#include "COptionsState.h"

CCreditsState::CCreditsState(void)
{

	m_bExitToMain = false;
	m_nFontID = -1;
	m_nTVImage = -1;
	m_nCreditsYLocation = 600;
	m_fCreditsMoveTimer  = 0;
	m_fInputTimer = 0;
	

}

CCreditsState::~CCreditsState(void)
{
}

void CCreditsState::Enter()
{
	//First selected object when you enter the state
	m_nCreditsYLocation = 600;
	m_cScreen.LoadScreen("Screens/BS_TallyScreen.xml");
	m_nFontID = CBitmapFontEngine::GetInstance()->LoadFont("BS_TechDemoTitle.xml");
	m_nTVImage = CSGD_TextureManager::GetInstance()->LoadTexture("Resource/ScreenImages/BS_TallyTVScreen.png");
	m_bExitToMain = false;
	m_fInputTimer = 0;
	m_fCreditsMoveTimer = 0;
}

void CCreditsState::Exit()
{
	m_bExitToMain = false;
}

bool CCreditsState::Input(float fElapsedTime)
{
	CWiimote* pWii = CWiimote::GetInstance();
	CSGD_DirectInput* pDI = CSGD_DirectInput::GetInstance();

	if (m_fInputTimer >= 0.01f && (pWii->IsButtonPressed(WII_UP) || pDI->KeyDown(DIK_UP)))
	{
		m_fInputTimer = 0;
		m_nCreditsYLocation -= 4; 
	}
	else if ( m_fInputTimer >= 0.01f && (pWii->IsButtonPressed(WII_DOWN) || pDI->KeyDown(DIK_DOWN)) )
	{
		m_fInputTimer = 0;
		m_nCreditsYLocation += 4; 
	}

	if ((pWii->IsButtonPressed(WII_HOME) || pDI->KeyPressed(DIK_ESCAPE)) || (pWii->IsButtonPressed(WII_A) || pDI->KeyPressed(DIK_RETURN)))
	{
		CSoundManager::GetInstance()->PlaySoundIndxUnBuffered(SOUND_MENU_SELECT);
		m_bExitToMain = true;
	}	
	return true;
}

void CCreditsState::Update(float fElapsedTime)
{



	if (m_fCreditsMoveTimer >= 0.05f && m_fInputTimer > 0)
	{
		m_nCreditsYLocation -= 2; 
		m_fCreditsMoveTimer = 0;
	}	

	m_fCreditsMoveTimer+= fElapsedTime;
	m_fInputTimer+= fElapsedTime;
	if (m_bExitToMain)
	{
		CTransitionScreen::GetInstance()->ChangeTo(CMainMenuState::GetInstance()); 
	}

}

void CCreditsState::Render()
{

	m_cScreen.RenderScreen();

	//////////////////////////////////////////////////////////////////////////
	//Location Setup
	//////////////////////////////////////////////////////////////////////////
	static CBitmapFontEngine* pBFE = CBitmapFontEngine::GetInstance();
	static CSGD_TextureManager* pTM = CSGD_TextureManager::GetInstance();
	static int GREEN = 0xFF00FF00;
	static int YELLOW = 0xFFFFFF00;
	static int Blue = 0xFF0000FF;
	//////////////////////////////////////////////////////////////////////////
	
	
	//////////////////////////////////////////////////////////////////////////
	//CREDITS
	pBFE->RenderString("CREDITS",m_nFontID,0,GREEN,180,m_nCreditsYLocation,0);
	pBFE->RenderString("PRODUCERS:",m_nFontID,0,GREEN,90,m_nCreditsYLocation + 100,0);
	pBFE->RenderString("DUSTIN CLINGMAN",m_nFontID,0,YELLOW,115,m_nCreditsYLocation + 130,0);
	pBFE->RenderString("KEYVAN ACOSTA",m_nFontID,0,YELLOW,115,m_nCreditsYLocation + 160,0);
	pBFE->RenderString("ASSOCIATE PRODUCER:",m_nFontID,0,GREEN,90,m_nCreditsYLocation + 230,0);
	pBFE->RenderString("JOHN OLESKE",m_nFontID,0,YELLOW,115,m_nCreditsYLocation + 260,0);
	pBFE->RenderString("ART DIRECTOR:",m_nFontID,0,GREEN,90,m_nCreditsYLocation + 330,0);
	pBFE->RenderString("CHRIS JAHOSKY",m_nFontID,0,YELLOW,115,m_nCreditsYLocation + 360,0);
	pBFE->RenderString("BLUE SMOKE TEAM:",m_nFontID,0,Blue,85,m_nCreditsYLocation + 430,0);
	pBFE->RenderString("TECH OFFICER:",m_nFontID,0,GREEN,90,m_nCreditsYLocation + 460,0);
	pBFE->RenderString("RYAN BURKEVICH",m_nFontID,0,YELLOW,115,m_nCreditsYLocation + 490,0);
	pBFE->RenderString("INTERFACE OFFICER:",m_nFontID,0,GREEN,90,m_nCreditsYLocation + 560,0);
	pBFE->RenderString("JAMES GONZALEZ",m_nFontID,0,YELLOW,115,m_nCreditsYLocation + 590,0);
	pBFE->RenderString("PROJECT OFFICER:",m_nFontID,0,GREEN,90,m_nCreditsYLocation + 660,0);
	pBFE->RenderString("KEITH MAGGIO",m_nFontID,0,YELLOW,115,m_nCreditsYLocation + 690,0);
	pBFE->RenderString("GAMEPLAY OFFICER:",m_nFontID,0,GREEN,90,m_nCreditsYLocation + 760,0);
	pBFE->RenderString("TRAVIS SETZ",m_nFontID,0,YELLOW,115,m_nCreditsYLocation + 790,0);

	pTM->Draw(m_nTVImage,0,0);
	//char buff[20];
	//(buff,"%d",m_nCreditsYLocation);
	//pBFE->RenderString(buff,m_nFontID,0,GREEN,100,200,0);

	//
	//////////////////////////////////////////////////////////////////////////


} 
